a = input()
r = []

def IsPrime(b):
    if b == 1: return False
    t = True
    k = b-1
    while k > 1:
        if not b%k:
            t = False
            break
        k -= 1
    return t

for i in range(len(a)):
    for k in range(i  +  1,len(a) + 1):
        c = int(a[i:k])
        if IsPrime(c):
            r += [c]


print(max(r) if r else 0)


